/** vlc插件
 * @file vlcwnd.hpp
 * @author Kiven Lee
 * @version 1.0
 * @date 2021-11-14
 *
 * @copyright Kivensoft (c) 2018 - 2021
 *
 */

#pragma once

#include <winsock2.h>
#include <windows.h>
#include <vlc/vlc.h>

namespace miniplayer {
    class VlcPlayer {
    private:
        libvlc_instance_t*          inst;
        libvlc_media_player_t*      player;
        libvlc_media_list_player_t* player_list;
        libvlc_media_t*             media;
        libvlc_media_list_t*        media_list;
        HWND                        hwnd;

        const char* play2(bool repeat);
        bool create_window();

    public:
        VlcPlayer();

        ~VlcPlayer() {
            stop();
            if (inst) libvlc_release(inst);
        }

        const char* play(const char* u8_path, bool repeat = true);
        const char* play_url(const char* url, bool repeat = true);

        void pause() { libvlc_media_player_pause(player); }

        void stop() {
            if (player) libvlc_media_player_stop(player);
            if (media_list) {
                libvlc_media_list_release(media_list);
                media_list = NULL;
            }
            if (media) {
                libvlc_media_release(media);
                media = NULL;
            }
            if (player) {
                libvlc_media_player_release(player);
                player = NULL;
            }
            if (player_list) {
                libvlc_media_list_player_release(player_list);
                player_list = NULL;
            }
            if (hwnd) {
                // ::CloseWindow(hwnd);
                ::DestroyWindow(hwnd);
                hwnd = NULL;
            }
        }
    };
} // namespace miniplayer
